package com.twang.stock.service.jinyan;

import com.twang.stock.entity.GaiNianZiJingPaiHang;
import com.twang.stock.mapper.GaiNianZiJingPaiHangMapper;
import com.twang.stock.dto.GaiNianZiJingPaiHangDto;
import com.twang.stock.utils.date.DateUtils;
import org.assertj.core.util.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * 查询板块概念
 */
@Service
@Slf4j
public class QueryBanKuaiRateService {

    @Resource
    private GaiNianZiJingPaiHangMapper gaiNianZiJingPaiHangMapper;

    @Autowired
    private HolidayService holidayService;

    public List<GaiNianZiJingPaiHangDto> queryBanKuaiRateService() {
        Example example = new Example(GaiNianZiJingPaiHang.class);
        Integer day=0;
        if(DateUtils.JudgeTime("00:00:00", "15:30:00") ){
            day=day+1;
        }else{
            day=day+0;
        }
        example.createCriteria().andEqualTo("date", holidayService.getDayByNumNotLimit(day));
        example.orderBy("zhangDie").desc();
        List<GaiNianZiJingPaiHang> list = gaiNianZiJingPaiHangMapper.selectByExample(example);
        List<GaiNianZiJingPaiHangDto> listDto = Lists.newArrayList();
        list.forEach(item -> {
            GaiNianZiJingPaiHangDto dto = new GaiNianZiJingPaiHangDto();
            BeanUtils.copyProperties(item, dto);
            listDto.add(dto);
        });
        return listDto;
    }

    //
    public List<GaiNianZiJingPaiHang> 查询板块by涨跌比() {
        Example example = new Example(GaiNianZiJingPaiHang.class);
        Example.Criteria criteria = example.createCriteria();
        Integer day=0;
        if(DateUtils.JudgeTime("00:00:00", "15:20:00") ){
            day=day+1;
        }else{
            day=day+0;
        }
        criteria.andEqualTo("date", holidayService.getDayByNumNotLimit(day));
        example.orderBy("zhangDie").desc();
        List<GaiNianZiJingPaiHang> list = gaiNianZiJingPaiHangMapper.selectByExample(example);
        return list.subList(0,12);
    }

    /**
     * 获取前日数据
     *
     * @return
     */
    public List<GaiNianZiJingPaiHangDto> queryBanKuaiRateBeforeYesterdayService() {
        Example example = new Example(GaiNianZiJingPaiHang.class);
        example.createCriteria().andEqualTo("date", gaiNianZiJingPaiHangMapper.getDate().get(2));
        example.orderBy("zhangDie").desc();
        List<GaiNianZiJingPaiHang> list = gaiNianZiJingPaiHangMapper.selectByExample(example);
        List<GaiNianZiJingPaiHangDto> listDto = Lists.newArrayList();
        list.forEach(item -> {
            GaiNianZiJingPaiHangDto dto = new GaiNianZiJingPaiHangDto();
            BeanUtils.copyProperties(item, dto);
            listDto.add(dto);
        });
        return listDto;
    }

    /**
     * 获取作日数据
     *
     * @return
     */
    public List<GaiNianZiJingPaiHangDto> queryBanKuaiRateYesterdayService() {
        Example example = new Example(GaiNianZiJingPaiHang.class);
        example.createCriteria().andEqualTo("date", gaiNianZiJingPaiHangMapper.getDate().get(1));
        example.orderBy("zhangDie").desc();
        List<GaiNianZiJingPaiHang> list = gaiNianZiJingPaiHangMapper.selectByExample(example);
        List<GaiNianZiJingPaiHangDto> listDto = Lists.newArrayList();
        list.forEach(item -> {
            GaiNianZiJingPaiHangDto dto = new GaiNianZiJingPaiHangDto();
            BeanUtils.copyProperties(item, dto);
            listDto.add(dto);
        });
        return listDto;
    }


}
